//
//  IMAdjustModels.m
//  DualMediationSDK
//
//  Created by YeJary on 2025/1/27.
//

#import "IMAdjustModels.h"

@implementation IMAdjustEventConfig

+ (instancetype)configWithEventId:(NSString *)eventId {
    IMAdjustEventConfig *config = [[IMAdjustEventConfig alloc] init];
    config.eventId = eventId;
    return config;
}

+ (instancetype)configWithEventId:(NSString *)eventId parameters:(NSDictionary<NSString *,NSString *> *)parameters {
    IMAdjustEventConfig *config = [self configWithEventId:eventId];
    config.parameters = parameters;
    return config;
}

+ (instancetype)configWithEventId:(NSString *)eventId revenue:(NSNumber *)revenue currency:(NSString *)currency {
    IMAdjustEventConfig *config = [self configWithEventId:eventId];
    config.revenue = revenue;
    config.currency = currency;
    return config;
}

- (BOOL)isValid {
    if (!self.eventId || self.eventId.length == 0) {
        return NO;
    }
    
    // 如果设置了收入，必须同时设置货币代码
    if (self.revenue && (!self.currency || self.currency.length == 0)) {
        return NO;
    }
    
    return YES;
}

- (NSString *)description {
    NSMutableString *desc = [NSMutableString stringWithFormat:@"IMAdjustEventConfig{eventId=%@", self.eventId];
    
    if (self.parameters && self.parameters.count > 0) {
        [desc appendFormat:@", parameters=%@", self.parameters];
    }
    
    if (self.revenue) {
        [desc appendFormat:@", revenue=%@", self.revenue];
    }
    
    if (self.currency) {
        [desc appendFormat:@", currency=%@", self.currency];
    }
    
    [desc appendString:@"}"];
    return desc;
}

@end

@implementation IMAdjustResult

+ (instancetype)successWithEventId:(NSString *)eventId {
    IMAdjustResult *result = [[IMAdjustResult alloc] init];
    result->_success = YES;
    result->_eventId = [eventId copy];
    result->_errorCode = 0;
    result->_errorMessage = nil;
    return result;
}

+ (instancetype)failureWithCode:(NSInteger)errorCode message:(NSString *)errorMessage {
    IMAdjustResult *result = [[IMAdjustResult alloc] init];
    result->_success = NO;
    result->_errorCode = errorCode;
    result->_errorMessage = [errorMessage copy];
    result->_eventId = nil;
    return result;
}

- (NSString *)description {
    if (self.success) {
        return [NSString stringWithFormat:@"IMAdjustResult{success=YES, eventId=%@}", self.eventId];
    } else {
        return [NSString stringWithFormat:@"IMAdjustResult{success=NO, errorCode=%ld, errorMessage=%@}", 
                (long)self.errorCode, self.errorMessage];
    }
}

@end